;; https://projecteuler.net/problem=1

;; Multiples of 3 and 5

;; Published on Friday, 5th October 2001, 06:00 pm; Solved
;; by 965258;

;; Difficulty rating: 5%

;; Problem 1

;; If we list all the natural numbers below 10 that are
;; multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of
;; these multiples is 23.

;; Find the sum of all the multiples of 3 or 5 below 1000.


(import
  (except (rnrs base) let-values)
  (only (guile)
        ;; lambda forms
        lambda* λ
        command-line)
  (srfi srfi-1))


(define sum
  (λ (nums)
    (reduce + 0 nums)))


(define multiples-of-3-and-5
  (λ (from-num to-num)
    (cond
     [(= from-num to-num)
      '()]
     [(or (= (remainder from-num 3) 0)
          (= (remainder from-num 5) 0))
      (cons from-num
            (multiples-of-3-and-5 (+ from-num 1) to-num))]
     [else
      (multiples-of-3-and-5 (+ from-num 1) to-num)])))


(simple-format
 (current-output-port)
 "~a\n"
 (sum
  (multiples-of-3-and-5
   0 (string->number (second (command-line))))))
